<?
header('content-type:text/html;charset=utf-8');
class Admin_Kind_Controller extends Base_Controller {

	public function action_index()
	{
    	$kinds = DB::table('article_kind')->order_by('id','asc')->paginate(5);;
        $username = Session::get('username');
        $count = DB::table('article_kind')->count();
        $all = ceil($count/5);
        return View::make('admin/kind',array('username'=>$username,'kinds'=>$kinds,'all'=>$all));
	}


	public function action_change()
    {   
        $id = $_GET['id'];
        $username = Session::get('username');
        $str = DB::table('article_kind')->where('id','=',$id)->first();
        return View::make('admin/kindchange',array('username'=>$username,'str'=>$str));
       
    }



    public function action_dochange()
    {   
    	$username = Session::get('username');
        $id = Input::get('id');
        $king = Input::get('king');
        $explanation = 	Input::get('content');    
        $str = DB::table('article_kind')->where('id','=',$id)->update(array('king'=>$king,'explanation'=>$explanation));
        if($str){
        	return View::make('jump/error2',array('msg'=>'修改成功.....','time'=>2,'url'=>'index'));
        }else{
        	return View::make('jump/error',array('msg'=>'修改失败','time'=>3));
        }      
    }


    public function action_dele()
    {   
    	$username = Session::get('username');
        $id = Input::get('id');   
        $str = DB::table('article_kind')->where('id','=',$id)->delete();
        $str1 = DB::table('article_content')->where('kid','=',$id)->delete();
        if($str||$str1){
        	return View::make('jump/error2',array('msg'=>'修改成功.....','time'=>2,'url'=>'index'));
        }else{
        	return View::make('jump/error',array('msg'=>'删除失败','time'=>3));
        }      
    }



    public function action_add()
    {   
    	$username = Session::get('username');
        return View::make('admin/kindadd',array('username'=>$username));
    }



    public function action_doadd()
    {   
    	$username = Session::get('username');
        $king = Input::get('king');
        $explanation = Input::get('content');
        $str = DB::table('article_kind')->insert(array('king'=>$king,'explanation'=>$explanation));
       if($str){
        	return View::make('jump/error2',array('msg'=>'添加成功.....','time'=>2,'url'=>'index'));
        }else{
        	return View::make('jump/error',array('msg'=>'添加失败','time'=>3));
        }     
    }






}